package online.hxstart.code.concurrent.chapter02;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author huxing
 * @date 19-4-23 星期二 下午3:20
 * @describe
 */
public class ThreadCounter extends Thread {
  static final AtomicInteger COUNTER = new AtomicInteger(0);

  public static void main(String[] args) {
    try {
      while (true) {
        new ThreadCounter().start();
      }
    } catch (Throwable e) {
      System.out.println("failed At => " + COUNTER.get());
    }
  }

  @Override
  public void run() {
    try {
      System.out.println("The " + COUNTER.getAndIncrement() + " thread be create.");
      TimeUnit.MINUTES.sleep(10);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
